import 'package:flutter/material.dart';



// 步骤条
class StepperCompontVertical extends StatefulWidget {
  final int currentStep;  // 当前第几步
  final List children;   // 列表组
  final dynamic onClick;        // 点击事件
  final double width;           // 宽度 



  StepperCompontVertical({
    Key key,
    this.currentStep=0,
    this.children,
    this.onClick,
    this.width=410,



  }) : super(key: key);  

  @override
  _StepperCompontVerticalState createState() => new _StepperCompontVerticalState();
}


class _StepperCompontVerticalState extends State<StepperCompontVertical> {


  // // 遍历 步骤条  
  // Widget _bodyInit() {

  //   if( widget.children!=null && widget.children.length>=1 ){
  //     List _child=widget.children;   // 子级
  //     // int _step=(widget.currentStep+1>=_child.length)?_child.length:widget.currentStep;  // 节点
  //     int _step=widget.currentStep-1;  // 节点
      
  //     List<Step> _list = [];

  //     // Widget content; 
  //     for(var i = 0; i < _child.length; i++){
  //       _list.add(
  //         Step(
  //           title: Text(
  //             _child[i]["title"]!=null?_child[i]["title"]:'',
  //             // overflow: TextOverflow.visible,
  //           ),
  //           subtitle: Text(
  //             _child[i]["content"]!=null?_child[i]["content"]:'',
  //             // overflow: TextOverflow.visible,
  //           ),
  //           content: Text(""),
  //           // state: StepState.error
  //           isActive: (i<_step)?true:false
  //         )
  //       );
  //     }

  //     return Stepper(
  //       currentStep: _step,
  //       type: StepperType.horizontal,
  //       steps:_list,     
  //       controlsBuilder: (BuildContext context,{VoidCallback onStepContinue, VoidCallback onStepCancel}){
  //         return Container();
  //       },
  //       onStepTapped: (index) {
  //         if( widget.onClick!=null ){
  //           widget.onClick(index);
  //         }
  //         // print("jins dsd");
  //       },
  //       onStepCancel: () {
  //         // print("You are clicking the cancel button.");
  //       },
  //       onStepContinue: () {
  //         // print("You are clicking the continue button.");
  //       },
  //     );
  //   }

  //   return null;
  // }



  @override
  Widget build(BuildContext context) {

    return Container(
      height: 75,
      // padding: EdgeInsets.fromLTRB(8,8,8,8),
      child: ListView(
        scrollDirection: Axis.horizontal,
        children: <Widget>[
          Container(
            width: widget.width,
            // color: Colors.red,
            child: Stepper(
              currentStep:widget.currentStep,
              type: StepperType.horizontal,
              // steps: widget.children.asMap().keys.map((i) => Step(
              steps: ( (widget.children.length)==0?[{}]:widget.children ).asMap().keys.map((i) => Step(
                title: Container(
                  child: Row(
                    children: [
                      Container(
                        child: (i==widget.currentStep) ? Icon(Icons.done,color: Colors.blue):null,
                      ),
                      Text(
                        ( widget.children.length!=0 && widget.children[i]["title"]!=null)?widget.children[i]["title"]:'',
                        style: TextStyle(
                          color: (i==widget.currentStep) ? Colors.blue : Colors.black
                        )
                        // overflow: TextOverflow.visible,
                      ),
                    ],
                  ),
                ),
                subtitle: Text(
                  ( widget.children.length!=0 && widget.children[i]["content"]!=null)?widget.children[i]["content"]:'',
                  style: TextStyle(
                    color: (i==widget.currentStep) ? Colors.blue : Colors.black
                  )                  
                  // overflow: TextOverflow.visible,
                ),
                content: Text(""),
                // state: StepState.error
                // isActive: (i<_step)?true:false
                isActive: ( (widget.children.length>=2) && (i<widget.children.length-1))?true:false
              )).toList(),            
              controlsBuilder: (BuildContext context,{VoidCallback onStepContinue, VoidCallback onStepCancel}){
                return Container();
              },
              onStepTapped: (index) {
                if( widget.onClick!=null ){
                  widget.onClick(index);
                }
                // print("jins dsd");
              },
              onStepCancel: () {
                // print("You are clicking the cancel button.");
              },
              onStepContinue: () {
                // print("You are clicking the continue button.");
              },
            )
          )            
        ],
      ),
    );
  }


}